home *** CD-ROM | disk | FTP | other *** search
- #INSTALLATION PROGRAM FOR WEBTEACHER'S WEBDATA 2.3x
- #
- #TO USE, PLACE THIS SCRIPT AND THE webdata.cgi SCRIPT IN
- #A DIRECTORY UNDER YOUR HOMEPAGES. (ie. viewable from the web).
- #THEN, FROM A COMMAND LINE, TYPE: perl install.pl
- #DETAILS ABOUT EACH QUESTION ARE IN THE readme.html FILE.
- #
-
-
- if ($^O=~/Win/i) {
- $slash="\\\\";
- $isUnix=0;
- } else {
- $slash="/";
- $isUnix=1;
- }
-
-
- print "
- Welcome to the installer program for webdata, the easiest database program
- for the world wide web. The installer will ask you a few questions about
- your server. You should complete the worksheet included in the readme.html
- document before continuing. By pressing \'y\' you are agreeing to absolve the
- authors of all liability related to use of this program.
-
- Would you like to continue? [y,n]
- ";
- $_ = <STDIN>;
- if (/^n/i) {exit;};
-
- &detect;
-
- print "
- Choose a short name for this database:
- ";
- $dbname=<STDIN>;
- chop($dbname);
-
- $webdata = "webdata_$dbname".".pl";
- $userform = $dbname."_form.html";
- $admin = $dbname."_admin.html";
- $memberentry = $dbname."_members.html";
- $instantmember= $dbname."_instantmember.html";
- $webdatafields = $dbname."_fields.log";
- $datalog = $dbname."_data.log";
- $memberfile = $dbname."_members.log";
- $reportpref= $dbname."_report.log";
-
- print "\n\n
- CGI scripts can live in one of two places, depending on
- how your server is configured. If your server uses the
- cgi-bin directory, you will be prompted for the path
- to the cgi-bin, and this installer will move the
- program there. Otherwise, if your server allows you to execute
- CGI scripts in any directory, you can place them with
- the HTML pages in any directory under your homepage.
- ";
- print "\n
- Where will the CGI scripts live on your server?
- 1. In the cgi-bin directory
- 2. In the same directory as the HTML pages
- 3. I'm not sure
- ";
- $cgichoice = <STDIN>;
- if ($cgichoice==1) {&cgibin}
- elsif ($cgichoice==2) {
- $webdata="webdata_$dbname".".cgi";
- $dirname=$webdata;
- }
- else {¬sure};
-
- if ($isUnix) {
- $isPerl5=0;
- @possiblePaths=('/usr/bin/perl','/usr/local/bin/perl','/usr/bin/perl5','/usr/local/bin/perl5');
- foreach (@possiblePaths) {
- $testpath=`$_ -v`;
- if ($testpath =~ /v(ersion)?[ \.]*([5-9])/i) {
- print "\nPerl $1 has been detected at $_\n";
- $isPerl5=1;
- $perlpath=$_;
- last;
- }
- }
-
-
- while (!$isPerl5) {
- print "\nWhat is the PATH to Perl version 5 on your machine? \n";
- $perlpath = <STDIN>;
- chop($perlpath);
- $testpath=`$perlpath -v`;
- if ($testpath =~ /version [5-9]/i) {
- $isPerl5=1;
- } else {
- print "$perlpath is not a valid path to Perl 5. \n$perlpath -v returned this:\n$testpath\n\n";
- print "Please enter another path, or press [CTRL]-c to quit \nand check with your system administrator.\n";
- }
- }
- if (!($perlpath =~ /^\//)) {$perlpath = "/$perlpath"};
- }
-
- $password=" ";
- $now=$now*307;
- until ($password eq $second) {
- if ($password ne " ") {print "Not a match, try again.\n\n"};
- print "\nWhat would you like your password to be?\n";
- $password = <STDIN>;
- print "\nPlease enter your password again.\n";
- $second = <STDIN>;
- }
- chop($password);
- print "\n";
-
- open(CGIREAD,"<webdata.cgi");
- @lines = <CGIREAD>;
- close CGIREAD;
- if ($isUnix) {
- $path = `pwd`;
- } else {
- $path = `chdir`;
- }
- chop($path);
- $idcode=substr($now,-4);
- if (length($oc)>0) {$idcode=$oc};
-
- print "\nThe ABSOLUTE PATH to the current directory is $path\n";
- print "What is the URL to the current directory?\n";
- print "(start with http://)\n";
- $pathurl=<STDIN>;
- chop($pathurl);
- chop($pathurl) if $pathurl=~/\/$/;
- if (!(-e './uploads')) {
- if (!mkdir(uploads,0777)) {
- print "ERROR! Could not create uploads directory in $path \n";
- print "Check that you have write permission to this directory.\n\n";
- exit;
- }
- }
- $cmd=`chmod 777 uploads` if $isUnix;
- $uploadsdir="$path";
- if (!$isUnix) {$uploadsdir=~s#\\#\\\\#g};
- $uploadsdir.="${slash}uploads${slash}";
- $uploadsURL="${pathurl}/uploads/";
-
- if ($cgichoice==1) {
- $logdir=$pathToCgiBin;
- } else {
- &getLogDir;
- }
-
- sub getLogDir {
- print "\nThe log files contain all of your data, fields, members, and preferences.
- For security reasons, we recommend you store these files in a directory which outside the
- viewable web pages. A typical directory structure might look like this:
-
- |-----------|
- | top level |
- |___________|
- / \\
- / \\
- |----------------| |---------------|
- | all .html pages| | logfiles |
- | and other web | | (not viewable |
- | related stuff | | via the web) |
- |________________| |_______________|
-
- ";
- $isLogdir=0;
- until($isLogdir) {
- print "Your current directory path is $path
- Enter the path to the directory you would like to use for the log files.
- If the directory you enter does not exist, the installer will try to create it.
- Press [ENTER] to use the current directory.
- ";
- $logdir=<STDIN>;
- chop($logdir);
- $wherelogs=0;
- while ($logdir =~ /^\./) {
- print "\nPlease use absolute paths only\n";
- print "Enter the path to the directory you would like to use for the log files.\n";
- print "Press [ENTER] to use the current directory.\n";
- $logdir=<STDIN>;
- chop($logdir);
- }
- if ($logdir =~/^$/) {$wherelogs='2'}
- if (!(-e $logdir)) {
- if (!mkdir($logdir,0755)) {
- while($wherelogs!~/1|2/) {
- print "The installer did not find $logdir and could not create it.\n\n";
- print "Please choose what you would like to do:\n";
- print " 1) Enter another path for the logs directory.\n";
- print " 2) Put the logs in the current directory for now.\n";
- $wherelogs=<STDIN>;
- chop($wherelogs);
- };
- if ($wherelogs==2) {
- print "\nThe log files will be placed in the current directory, $path \n";
- print "If you wish to move them later, simply change the value of \$logdir \n";
- print "in line 10 of the $webdata script.\n\n\n\n";
- $logdir="${path}";
- $isLogdir=1;
- };
- } else {
- print "\nCreated new directory at $logdir\n\n";
- $isLogdir=1;
- };
- } else {
- $isLogdir=1;
- };
- };
- print "Press [ENTER] to continue...\n";
- $tmp=<STDIN>;
- }
-
- $logdirDisplay=$logdir;
- $logdirDisplay=~s#\\#\\\\#g;
- $logdir.=$slash if ($logdir!~/${slash}$/);
- $logdirDisplay.=$slash if ($logdirDisplay!~/${slash}$/);
- $logdirDisplay="" if $cgichoice==1;
-
-
- $lines[0]='#!'."$perlpath\n";
- $lines[5]="\$uploadsdir=\'$uploadsdir'\; #Must end with a $slash\n";
- $lines[6]="\$uploadsURL=\'$uploadsURL'\; #Must end with a /\n";
- $lines[7]="\$password=\"$password\"\;\n";
- $lines[9]="\$logdir=\'$logdirDisplay'\; #Must end with a $slash or is empty if log files are local to script.\n";
- $lines[11]="\$logfile=\"\${logdir}$datalog\"\;\n";
- $lines[12]="\$fieldnames=\"\${logdir}$webdatafields\"\;\n";
- $lines[13]="\$members=\"\${logdir}$memberfile\"\;\n";
- $lines[14]="\$reportdata=\"\${logdir}$reportpref\"\;\n";
- $lines[15]="\$code=\'$idcode\'\;\n";
-
- foreach (@lines) {
- if (/<!--FLAG5-->/) {$_="\$key=$now\; #<!--FLAG5-->\n"};
- };
-
-
- open(CGIWRITE,">$webdata");
- print CGIWRITE (@lines);
- close CGIWRITE;
-
- sub cgibin {
- $dirname="/cgi-bin/$webdata";
- $valid="false";
-
- if ($isUnix) {
- $path = `pwd`;
- } else {
- $path = `chdir`;
- }
- chop($path);
- @cgipaths=split(/[\\\/]/,$path);
- while ($#cgipaths>=0) {
- $cgitestpath=join($slash,@cgipaths,"cgi-bin");
- $cgitestpath=~s/\\\\/\\/g;
- if (-e $cgitestpath) {
- push(@cgiresults,$cgitestpath);
- }
- pop(@cgipaths);
- }
- if ($#cgiresults>-1) {
- print "\nA directory named cgi-bin has been detected at the following location(s):\n\n";
- for($i=1;$i<=$#cgiresults+1;$i++) {
- print "\t$i\. $cgiresults[$i-1]\n"
- };
- print "\n\nIf the correct path to the cgi-bin is shown above,
- enter the number to its left. Otherwise, press [ENTER].\n\n";
- };
-
- $cgiselection=<STDIN>;
- chop($cgiselection);
- if ($cgiselection=~/[1-$i]/) {
- $cgiselection--;
- $pathToCgiBin=$cgiresults[$cgiselection];
- $valid="true";
- }
-
-
- while ($valid eq "false") {
- print "\nPlease enter the path to the /cgi-bin/ directory:\n";
- $pathToCgiBin = <STDIN> ;
- chop($pathToCgiBin);
- $_=$pathToCgiBin;
- if ($isUnix) {
- if (!(/^\//)) {$pathToCgiBin = "/$pathToCgiBin";};
- if (!(/\/$/)) {$pathToCgiBin = "$pathToCgiBin/";};
- };
- if (!(-e $pathToCgiBin)) {
- print "\n\nPath is invalid. ";
- print "Try again, or press [CTRL]-c to exit.\n";
- } else {
- $valid="true";
- };
- };
- };
-
- sub notsure {
- print "
- If this is your first CGI, you need to know a little bit about
- the way your server is configured. Ask your system administrator
- where you are permitted to have CGI scripts on this server. We
- also recommend reading the first 5 pages of the CGI tutorial at
- http://www.webteacher.com/perltour
-
- It will help you feel a lot more comfortable with your server, and
- the Unix environment in general. \n\n";
-
-
- print "
- This program will now exit. You
- should run it again when you know whether your server requires the
- CGI scripts to be in the /cgi-bin/ directory or not.
- ";
- exit;
- };
- print "\n
- The Installer will help you define your list of fields.
- Fields are the attributes you wish to record about each entry,
- for example, FirstName, LastName, Color, Make, Model, EntryDate,
- PartNumber, etc.
-
- Press [ENTER] when you are finished entering fields. If you make a mistake,
- press [ENTER] and choose No when asked if you are satisfied with the list.
-
- ";
-
- $tryagain="true";
- while ($tryagain eq "true") {
- $time = time();
- @fields = ("webdata$time\n");
- print "Enter a field name: ";
- $field = <STDIN>;
- push(@fields,$field);
- $morefields="true";
- while ($morefields eq "true") {
- print "Enter another field name: ";
- $field = <STDIN> ;
- push(@fields,$field);
- $_=$field;
- if (/./) {$morefields = "true"} else {$morefields = "false"};
- };
- print "\n";
- pop(@fields);
- foreach $field (@fields) {
- if (substr($field,0,7) ne 'webdata') {print "$field"};
- };
-
- print "\nAre you satisfied with the field list? (y/n)";
- print "[Type \'y\' to keep the list, \'n\' to enter the fields again]";
- $tryagain = <STDIN>;
- $_=$tryagain;
- if (/^y/i) {$tryagain = "false"} else {$tryagain = "true"}
- };
-
- foreach (@fields) {
- chop($_);
- $_=$_."::text:20\n";
- };
- if (length($odb)>0) {
- @fields[0]=$odb;
- }
- open(FIELDLIST,">${logdir}$webdatafields");
- print FIELDLIST (@fields);
- close FIELDLIST;
-
- $rc=@fields;
- for($i=0;$i<$rc-1;$i++) {
- $row.="$i:";
- };
- chop($row);
- open(REPORT,">${logdir}$reportpref");
- print REPORT
- ("BEIGE\n\n$row\n0\n0\n15\n0\n\n1\nview\n\n\n\n\n\n\n\n\n\n\n\nWHITE\nWHITE\nWHITE\n$row\n\n\n\n\n\n\n\n1\n$pathurl\n\n1\n1\n\n\n\n\n\nEnglish\n\n\n\n\n\n\n\n\n\n1\n\n\n1\n1\n1\n1\n\n");
- close REPORT;
- open(REPORT,">${logdir}$memberfile");
- print REPORT ("::nopass\n");
- close REPORT;
-
-
- open(FIELDS,"<$webdatafields");
- @fields = <FIELDS>;
- close FIELDS;
-
- open(FORM,">$userform");
- $loc=$dirname."?cgifunction=user";
- print FORM ("
- <script language=\"javascript\">
- location.replace(\'$loc\')\;
- </script>
- ");
- close FORM;
- qx(chmod 755 $userform) if $isUnix;
-
- open (ADMIN,">$admin");
- print ADMIN ("
- <HTML>
- <HEAD>
- <TITLE> Web Data Administration Password </TITLE>
- </HEAD>
-
- <BODY BGCOLOR=BEIGE onLoad=\"document.form1.password.focus()\">
- <H1 ALIGN=CENTER>
- YOU MUST HAVE A PASSWORD TO ENTER THE ADMINISTRATION SITE
- </H1>
-
- Enter password here:<BR>
- <FORM NAME=\"form1\" ACTION=\"$dirname\" METHOD=\"POST\">
- <INPUT TYPE=PASSWORD NAME=\"password\">
- <INPUT TYPE=HIDDEN NAME=\"cgifunction\" VALUE=\"admin\">
- <INPUT TYPE=SUBMIT VALUE=\"Enter\">
- </FORM>
-
- </BODY>
- </HTML>
-
- ");
- close ADMIN;
-
- open (MEMBERPAGE,">$memberentry");
- print MEMBERPAGE ("
- <HTML>
- <HEAD>
- <TITLE> Web Data Member Password </TITLE>
- </HEAD>
-
- <BODY BGCOLOR=BEIGE onLoad=\"document.form1.username.focus()\">
- <H1 ALIGN=CENTER>
- MEMBERS ENTRY PAGE.<BR>
- </H1>
-
- <TABLE BORDER=0>
- <FORM NAME=\"form1\" ACTION=\"$dirname\" METHOD=\"POST\">
- <TR><TD><B>User Name</B><TD><INPUT TYPE=TEXT NAME=\"username\" SIZE=20><BR>
- <TR><TD><B>Password</B><TD><INPUT TYPE=PASSWORD NAME=\"password\" SIZE=20><BR>
- </TABLE>
- <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"memberpage\">
- </FORM>
- </BODY>
- </HTML>
-
- ");
- close MEMBERPAGE;
-
- open (INSTANTMEMBER,">$instantmember");
- print INSTANTMEMBER ("
- <HTML>
- <HEAD>
- <TITLE> Web Data Member Password </TITLE>
- </HEAD>
-
- <BODY BGCOLOR=BEIGE onLoad=\"document.form1.username.focus()\">
- <H1 ALIGN=CENTER>
- Choose a Username and Password<BR>
- </H1>
-
- <TABLE BORDER=0>
- <FORM NAME=\"form1\" ACTION=\"$dirname\" METHOD=\"POST\">
- <TR><TD><B>User Name</B><TD><INPUT TYPE=TEXT NAME=\"username\" SIZE=20><BR>
- <TR><TD><B>Password</B><TD><INPUT TYPE=PASSWORD NAME=\"password\" SIZE=20><BR>
- </TABLE>
- <INPUT TYPE=SUBMIT NAME=\"cgifunction\" VALUE=\"instantmember\">
- </FORM>
- </BODY>
- </HTML>
-
- ");
- close INSTANTMEMBER;
-
- if ($isUnix) {
- qx(chmod 755 "$admin");
- qx(echo 111::Delete Me::admin > ${logdir}$datalog);
- qx(chmod 777 ${logdir}$datalog);
- qx(chmod 777 ${logdir}$webdatafields);
- qx(chmod 755 $webdata);
- qx(chmod 755 $memberentry);
- qx(chmod 755 $instantmember);
- qx(chmod 777 ${logdir}$reportpref);
- qx(chmod 777 ${logdir}$memberfile);
- }
- if ($cgichoice==1) {
- if ($isUnix) {
- qx(mv $webdata "$pathToCgiBin");
- } else {
- qx(move $webdata "$pathToCgiBin");
- };
- };
-
- if (!(-f 'index.html')) {
- open(BACKDOOR,">index.html");
- print BACKDOOR ("
- <BODY BGCOLOR=\"WHITE\">
- Four pages have been created for your convenience in the
- current directory ($path).
- <P>
- Guests should be linked to <A HREF=\"$userform\">$userform</A> to search your database
- <P>
- Administrators should go to <A HREF=\"$admin\">$admin</A> to add, modify, and remove records,
- import and export, modify fields, and add members.
- <P>
- Members with accounts can go to <A HREF=\"$memberentry\">$memberentry</A> to add and modify only
- their own records.
- <P>
- If you choose to allow instant members (admin preferences) you can direct
- new members to <A HREF=\"$instantmember\">$instantmember</A>.
- <P>
- ");
- close BACKDOOR;
- qx(chmod 755 index.html) if $isUnix;
- };
-
- print "
- Four pages have been created for your convenience in the
- current directory ($path).
-
- Guests should be linked to $userform to search your database
-
- Administrators should go to $admin to add, modify, and remove records,
- import and export, modify fields, and add members.
-
- Members with accounts can go to $memberentry to add and modify only
- their own records.
-
- If you choose to allow instant members (admin preferences) you can direct
- new members to $instantmember.
-
- If you have difficulty, please read the troubleshooting page at
- http://www.webteacher.com/perltour/testhelp.htm
-
- ";
-
- sub detect {
- if ($isUnix) {
- @installs=qx(ls);
- } else {
- @installs=qx(dir);
- }
- foreach (@installs) {
- if (/(webdata_.*\.(cgi|pl))/i) {
- $oldfile=$1;
- last;
- }
- }
- $now=time();
- if (length($oldfile)>0) {
- print "detected: $oldfile\n";
- open (OFL,"<$oldfile");
- @ofl=<OFL>;
- close OFL;
- if ($ofl[1]=~/2\.2/) {
- $oc=substr($ofl[14],7,4);
- $odb=substr($ofl[11],13,99);
- $odb=substr($odb,0,-3);
- open (ODB,"<$odb");
- @odbl=<ODB>;
- close ODB;
- $odb=$odbl[0];
- }
- if ($ofl[1]=~/2\.3/) {
- $oc=substr($ofl[15],7,4);
- if ($ofl[9]=~/\'(.+)\'/) {$odb=$1};
- $odb=~s#\\\\#\\#g;
- if ($ofl[12]=~/\}(.+)\"/) {$odb.=$1};
- open (ODB,"<$odb");
- @odbl=<ODB>;
- close ODB;
- $odb=$odbl[0];
- }
- print "Another copy if Webdata has been detected.
- The installer will match the registration info to the other database.
-
- Press [ENTER] to continue\n";
- $foobar=<STDIN>;
- };
- }
-
- print "Press [ENTER] to finish";
- $tmp=<STDIN>;
-